home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 1 / Mac Magazin and MacEasy Magazine CD - Issue 01.iso / Sharewarebibliothek / Powermac / C64 / SOURCE / Menus.c < prev    next >
Text File  |  1994-06-06  |  5KB  |  263 lines

  1. /*
  2.     Commodore 64 Emulator v0.4      Earle F. Philhower III 
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "Processor.h"
  21. #include "Menus.h"
  22. #include "Error.h"
  23. #include "Resources.h"
  24.  
  25. Handle menuBar;
  26. MenuHandle appleMenu, fileMenu, editMenu, deviceMenu;
  27. extern int programMode;
  28.  
  29. int MenuInitialize()
  30. {
  31.     menuBar=GetNewMBar(128);
  32.     if (menuBar==nil) return kMissingResource;
  33.     SetMenuBar(menuBar);
  34.     
  35.     appleMenu=GetMenu(kAppleMenu);
  36.     if (appleMenu==nil) return kMissingResource;
  37.     AddResMenu(appleMenu, 'DRVR');
  38.     
  39.     fileMenu=GetMenu(kFileMenu);
  40.     if (fileMenu==nil) return kMissingResource;
  41.     editMenu=GetMenu(kEditMenu);
  42.     if (editMenu==nil) return kMissingResource;
  43.     deviceMenu=GetMenu(kDeviceMenu);
  44.     if (deviceMenu==nil) return kMissingResource;
  45.     
  46.     DisableItem(editMenu, 1);
  47.     DrawMenuBar();
  48.     
  49.     return kNoError;
  50. }
  51.  
  52.  
  53. void DoMenuChoice(long menuChoice)
  54. {
  55.     int theMenu, theItem;
  56.     
  57.     if (menuChoice==0)
  58.     {
  59.         HiliteMenu(0);
  60.         return;
  61.     }
  62.  
  63.     theMenu=HiWord(menuChoice);
  64.     theItem=LoWord(menuChoice);
  65.  
  66.     HiliteMenu(theMenu);
  67.  
  68.     switch(theMenu)
  69.     {
  70.         case kAppleMenu:
  71.             DoAppleMenu(theItem);
  72.             break;
  73.             
  74.         case kFileMenu:
  75.             DoFileMenu(theItem);
  76.             break;
  77.             
  78.         case kEditMenu:
  79.             DoEditMenu(theItem);
  80.             break;
  81.             
  82.         case kDeviceMenu:
  83.             DoDeviceMenu(theItem);
  84.             break;
  85.     }
  86.  
  87.     HiliteMenu(0);
  88. }
  89.  
  90.  
  91. void DoAppleMenu(int theItem)
  92. {
  93.     EventRecord event;
  94.     Str255 daName;
  95.     DialogPtr dialog;
  96.     WindowPtr theWind;
  97.     int done;
  98.     
  99.     switch (theItem)
  100.     {
  101.         case kAbout:
  102.             /* Show About... window */
  103.             /* Don't draw it since MacOS will give us an update event */
  104.             dialog=GetNewDialog(kAboutDialog, nil, (WindowPtr)-1L);
  105.             SetWRefCon(dialog, kAboutWindow);
  106.             ShowWindow(dialog);
  107.             
  108.             /* Handle events until time to drop window */
  109.             done=0;
  110.             while (!done)
  111.             {
  112.                 WaitNextEvent(everyEvent, &event, 60L, nil);
  113.                 switch(event.what)
  114.                 {
  115.                 case mouseDown:
  116.                 case autoKey:
  117.                 case keyDown:
  118.                 /* On keypress or buttonpress stop waiting */
  119.                     done=1;
  120.                     break;
  121.                     
  122.                 case updateEvt:
  123.                     theWind=(WindowPtr)event.message;
  124.                     BeginUpdate(theWind);
  125.                     switch (GetWRefCon(theWind))
  126.                     {
  127.                     case kVICWindow:
  128.                         RedrawVIC();
  129.                         break;
  130.                     case kDirWindow:
  131.                         RedrawDir();
  132.                         break;
  133.                     case kAboutWindow:
  134.                         DrawDialog(dialog);
  135.                         break;
  136.                     }
  137.                     EndUpdate(theWind);
  138.                     break;
  139.                 }
  140.             }
  141.             
  142.             /* Drop window and redraw the VIC screen */
  143.             HideWindow(dialog);
  144.             DisposDialog(dialog);
  145.             TotalRedrawVIC();
  146.             break;
  147.             
  148.         default:
  149.             /* Run the selected Desk Accessory */
  150.             GetItem(appleMenu, theItem, daName);
  151.             OpenDeskAcc(daName);
  152.             break;
  153.         }
  154. }
  155.  
  156.  
  157. void DoFileMenu(int theItem)
  158. {
  159.     switch(theItem)
  160.     {
  161.         case kOpenRAM:
  162.             LoadRAM();
  163.             break;
  164.             
  165.         case kSaveRAM:
  166.             SaveRAM();
  167.             break;
  168.             
  169.         case kReset:
  170.             /* Clear the menu hilite, since we're gonna be away a while */
  171.             HiliteMenu(0);
  172.             /* Reset PC, memory map */
  173.             RegisterInitialize();
  174.             /* Go compute */
  175.             if (programMode!=kRunning) ProcessorLoop();
  176.             break;
  177.             
  178.         case kPageSetup:
  179.             break;
  180.             
  181.         case kPrint:
  182.             break;
  183.  
  184.         case kPrefs:
  185.             DoPrefs();
  186.             break;
  187.  
  188.         case kQuit:
  189.             CleanUpCommodore();
  190.             ExitToShell();
  191.             break;
  192.     }
  193. }
  194.  
  195.  
  196. void DoEditMenu(int theItem)
  197. {
  198.     switch(theItem)
  199.     {
  200.         case kUndo:
  201.             break;
  202.             
  203.         case kCut:
  204.             break;
  205.             
  206.         case kCopy:
  207.             break;
  208.             
  209.         case kPaste:
  210.             break;
  211.             
  212.         case kClear:
  213.             break;
  214.     }
  215. }
  216.  
  217.  
  218. void DoDeviceMenu(int theItem)
  219. {
  220.     switch(theItem)
  221.     {
  222.         case kCreateImage:
  223.             FloppyCreateImage();
  224.             break;
  225.             
  226.         case kSelectImage:
  227.             FloppySelectImage();
  228.             break;
  229.             
  230.         case kDirectory:
  231.             FloppyDirectory();
  232.             break;
  233.             
  234.         case kCopyTo:
  235.             FloppyCopyTo();
  236.             break;
  237.             
  238.         case kChdir:
  239.             HardChangeDirectory();
  240.             break;
  241.             
  242.         case kNewPFile:
  243.             PrinterNewFile();
  244.             break;
  245.         
  246.         case kAppendPFile:
  247.             PrinterAppendFile();
  248.             break;
  249.         
  250.         case kXvert:
  251.             PrinterXvertCharacters();
  252.             break;
  253.         
  254.         case kDisplayPFile:
  255.             PrinterDisplayFile();
  256.             break;
  257.         
  258.         case kLoadTape:
  259.             LoadTape();
  260.             break;
  261.     }
  262. }
  263.